package classes.utils
{
	import classes.*;
	
	public class Validator
	{
		public function Validator()
		{
		}
		
		public static function parseNumberString(num:String):Number{
			var number:Number = parseFloat(num);
			
			if(isNaN(number)){
				number = parseFloat(num.replace(/[$,]+/g, ""));
			}
			
			return number;
		}
		
		public static function validateTransaction(t:Transaction):Boolean{
			if(	t == null 			||
				t.category == ""	||
				t.recipient == ""	||
				isNaN(t.amount)		||
				t.amount == 0		)
			{
				return false;
			}
			
			if(t.date == null)
				t.date = new Date();
			
			return true;
		}
		
		public static function validateNewUserInfo(name:String, password:String, confirmPassword:String):Object{
			var failReason:String = "";
			
			if( name.length < 5)
				failReason = "Username must be at least 5 characters in length.";
			else if( password.length < 6 )
				failReason = "Password must be at least 6 characters in length.";
			else if(password != confirmPassword)
				failReason = "Passwords must match.";
			
			if(failReason != "")
			{
				return {valid:false,
						reason:failReason};
			}
			
			return {valid:true};
		}

	}
}